package str

import (
	"sort"
	"strings"
)

func GroupAnagrams(strs []string) [][]string {

	strMap := map[string][]string{}

	for i, v := range strs {
		str_list := strings.Split(v, "")
		sort.Strings(str_list)
		temp := strings.Join(str_list, "")
		if _, ok := strMap[temp]; !ok {
			strMap[temp] = make([]string, 0)
		}
		strMap[temp] = append(strMap[temp], strs[i])
	}

	res := [][]string{}

	for _, v := range strMap {
		res = append(res, v)
	}
	return res
}
